/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-04 15:01:07
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-04 22:30:39
 * @FilePath: \vue3_admin_template\project\src\store\modules\category.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//商品分类全局组件的小仓库
import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '@/api/product/attr'
import type { CategoryResponseData } from '@/api/product/attr/type'
import type { CategoryState } from '@/store/modules/type/types'
let useCategoryStore = defineStore('Category', {
  state: (): CategoryState => {
    return {
      //存储一级分类数据数组
      c1List: [],
      c1Id: '',
      //存储一级分类下二级分类数据数组
      c2List: [],
      c2Id: '',
      //存储二级分类下三级分类数据数组
      c3List: [],
      c3Id: '',
    }
  },
  actions: {
    async getC1() {
      const result: CategoryResponseData = await reqC1()
      if (result.code == 200) {
        this.c1List = result.data
      }
    },
    async getC2() {
      const result: CategoryResponseData = await reqC2(this.c1Id)
      if (result.code == 200) {
        this.c2List = result.data
      }
    },
    async getC3() {
      const result: CategoryResponseData = await reqC3(this.c2Id)
      if (result.code == 200) {
        this.c3List = result.data
      }
    },
  },
  getters: {},
})

export default useCategoryStore
